package com.hades.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if("123456".equals(username) && "123456".equals(password)){
            Cookie usernameCookie = new Cookie("username",username);
            usernameCookie.setMaxAge(60*60*24*7);// 用户名保存7天
            resp.addCookie(usernameCookie);
            System.out.println("登陆成功");
        }else {
            System.out.println("登陆失败");
        }
    }
}
